using I2.Loc;
using UnityEngine;

public class InAppProduct : MonoBehaviour
{
	public UILabel lbMoney;

	public UILabel lbGiveCoins;

	public UILabel lbTypeCash;

	public UILabel lbAlternativePrice;

	public UISprite redLine;

	public GameObject but;

	public GameObject butNoActiv;

	public string packNameForFlurry;

	public float packPriceForFlurry;

	public string IdItemsIOS = string.Empty;

	public string IdItemsAndroid = string.Empty;

	public string idItems;

	public MoneyType coinsId;

	public int kolAddMoney;

	public SaveInt kolAddMoneySave;

	private SaveInt kolAddMoneySaveWithoutX3;

	public int alternativePrice;

	public SaveInt alternativePriceSave;

	[Header("Info inapp")]
	public float dollarPrice;

	[HideInInspector]
	public int nomProduct;

	[HideInInspector]
	public bool productEnabled;

	public bool showByKey;

	public string keyForShow;

	public UILabel x3price;

	public GameObject x3Sprite;

	public bool showGoldX3 = true;

	public bool promoEnabled;

	private Color _defaultCountColor;

	private int _moneyCount;

	private Vector3 normalScale;

	public float scaleModifer = 2f;

	public bool canBuy;

	public bool isSubscription;

	public ChestButton chest;

	public int alternativeGold;

	private bool _moneyCountInited;

	private bool _rulePlatformSetted;

	private void Awake()
	{
		if (x3Sprite == null)
		{
			x3Sprite = base.transform.FindChild("X3Sprite").gameObject;
		}
		if (x3price == null)
		{
			x3price = x3Sprite.transform.FindChild("Count").GetComponent<UILabel>();
		}
		x3Sprite.gameObject.SetActive(false);
		chest = GetComponentInChildren<ChestButton>();
		alternativePriceSave = alternativePrice;
		if (lbAlternativePrice != null)
		{
			lbAlternativePrice.text = alternativePriceSave.ToString();
		}
		DisableSubscription();
	}

	private void Start()
	{
		if (lbGiveCoins != null)
		{
			_defaultCountColor = lbGiveCoins.color;
		}
		InitMoneyCount();
		InAppPromoController.InAppPromo promoById = InAppPromoController.instance.inAppPromos.GetPromoById(idItems);
		if (promoById != null && promoById.Enabled && promoById.inAppPar > 0)
		{
			InitMoneyCount(promoById.inAppPar);
			if (promoById.promoBonuses.cashAmount == 0 && promoById.promoBonuses.goldAmount == 0)
			{
				lbGiveCoins.gameObject.SetActive(false);
				if (redLine != null)
				{
					redLine.gameObject.SetActive(false);
				}
			}
			if (promoById.inAppShowingPrice > 0f)
			{
				dollarPrice = promoById.inAppShowingPrice;
			}
		}
		if (isSubscription)
		{
			x3Sprite.gameObject.SetActive(false);
			lbGiveCoins.color = _defaultCountColor;
			if (redLine != null)
			{
				redLine.gameObject.SetActive(false);
			}
			if (InAppSubscriptionsController.instance.Promo.inAppShowingPrice > 0f)
			{
				dollarPrice = InAppSubscriptionsController.instance.Promo.inAppShowingPrice;
			}
		}
		normalScale = lbGiveCoins.transform.localScale;
		if (Application.platform == RuntimePlatform.Android)
		{
			base.gameObject.SetActive(!LicenseChecker.CheckHostsTampering());
		}
		setRuleIdPlatform();
		if (lbGiveCoins != null)
		{
			lbGiveCoins.transform.localScale = Vector3.one;
		}
		if (_moneyCount > 0)
		{
			lbGiveCoins.text = (alternativeGold + _moneyCount).ToString();
		}
		if (lbMoney != null)
		{
			lbMoney.text = InAppShop.instance.ConverctCurrency(idItems);
		}
		if (lbMoney.text == string.Empty)
		{
			lbMoney.text = dollarPrice + " $";
		}
	}

	public void SetlbGiveCoins(int val)
	{
		alternativeGold = val;
		lbGiveCoins.text = (alternativeGold + _moneyCount).ToString();
	}

	public void InitMoneyCount(int count)
	{
		kolAddMoney = count;
		_moneyCount = kolAddMoney;
		kolAddMoneySave = kolAddMoney;
		kolAddMoneySaveWithoutX3 = kolAddMoney;
		PromoPriceUpdate(true);
		_moneyCountInited = true;
	}

	public void InitMoneyCount()
	{
		if (!_moneyCountInited)
		{
			_moneyCount = kolAddMoney;
			kolAddMoneySave = kolAddMoney;
			kolAddMoneySaveWithoutX3 = kolAddMoney;
			_moneyCountInited = true;
		}
	}

	private void OnEnable()
	{
		DisableSubscription();
		switch (coinsId)
		{
		case MoneyType.Gold:
			lbTypeCash.text = ScriptLocalization.Get("Lobby_ShopCoins/lb_Gold");
			break;
		case MoneyType.Cash:
			lbTypeCash.text = ScriptLocalization.Get("Lobby_ShopCoins/lb_Cash");
			break;
		}
		if (chest != null)
		{
			chest.UpdateState();
		}
	}

	private void OnDisable()
	{
	}

	private void OnDestroy()
	{
	}

	public void DisableSubscription()
	{
		if (isSubscription && InAppSubscriptionsController.instance != null && !InAppSubscriptionsController.instance.Promo.Enabled)
		{
			base.gameObject.SetActive(false);
		}
	}

	public void setRuleIdPlatform()
	{
		if (!_rulePlatformSetted)
		{
			if (Application.platform == RuntimePlatform.OSXEditor)
			{
				idItems = IdItemsIOS;
			}
			if (Application.platform == RuntimePlatform.IPhonePlayer)
			{
				idItems = IdItemsIOS;
			}
			if (Application.platform == RuntimePlatform.Android)
			{
				idItems = IdItemsAndroid;
			}
			_rulePlatformSetted = true;
		}
	}

	public void reset()
	{
		nomProduct = -1;
		productEnabled = false;
		canBuy = false;
		if (but != null)
		{
			but.SetActive(false);
		}
		if (butNoActiv != null)
		{
			butNoActiv.SetActive(true);
		}
		if (lbMoney != null)
		{
			lbMoney.text = InAppShop.instance.ConverctCurrency(idItems);
		}
		if (lbMoney.text == string.Empty)
		{
			lbMoney.text = dollarPrice + " $";
		}
	}

	public void vklBut()
	{
		canBuy = true;
		if (but != null)
		{
			but.SetActive(true);
		}
		if (butNoActiv != null)
		{
			butNoActiv.SetActive(false);
		}
	}

	public void X3Update()
	{
		if (EventX3Manager.Instance != null)
		{
			if (EventX3Manager.Instance.IsEventX3Active)
			{
				x3Sprite.gameObject.SetActive(false);
				x3price.text = (kolAddMoney * 3).ToString();
				lbGiveCoins.applyGradient = false;
				lbGiveCoins.color = Color.gray;
				kolAddMoney = _moneyCount * 3;
				kolAddMoneySave = (int)kolAddMoneySaveWithoutX3 * 3;
				lbGiveCoins.transform.localScale = normalScale / scaleModifer;
			}
			else
			{
				x3Sprite.gameObject.SetActive(false);
				lbGiveCoins.applyGradient = true;
				lbGiveCoins.color = _defaultCountColor;
				kolAddMoney = _moneyCount;
				kolAddMoneySave = kolAddMoneySaveWithoutX3;
				lbGiveCoins.text = string.Empty + _moneyCount;
				lbGiveCoins.transform.localScale = normalScale;
			}
		}
	}

	public void PromoPriceUpdate(bool ignoreX3)
	{
		x3Sprite.gameObject.SetActive(false);
		x3price.text = (kolAddMoney * (ignoreX3 ? 1 : 3)).ToString();
		lbGiveCoins.applyGradient = false;
		lbGiveCoins.color = Color.white;
		kolAddMoney = _moneyCount * (ignoreX3 ? 1 : 3);
		kolAddMoneySave = (int)kolAddMoneySaveWithoutX3 * (ignoreX3 ? 1 : 3);
		lbGiveCoins.transform.localScale = normalScale / scaleModifer;
	}

	public static int Comparator(InAppProduct a, InAppProduct b)
	{
		if (a == null || b == null)
		{
			return 0;
		}
		if (a.promoEnabled)
		{
			return -1;
		}
		if (b.promoEnabled)
		{
			return 1;
		}
		if (a.isSubscription)
		{
			return -1;
		}
		if (b.isSubscription)
		{
			return 1;
		}
		if (FlurryWrapper.IsPayingUser())
		{
			return (!(a.dollarPrice > b.dollarPrice)) ? 1 : (-1);
		}
		return (a.dollarPrice > b.dollarPrice) ? 1 : (-1);
	}
}
